package com.youease.chris.view.mediator
{
	import com.youease.chris.control.MapSceneCommand;
	import com.youease.chris.control.RandomMapCommand;
	import com.youease.chris.manager.GlobalObject;
	import com.youease.chris.model.proxy.MapDataProxy;
	import com.youease.chris.model.vo.MapData;
	import com.youease.chris.view.MapProperties;
	import com.youease.chris.view.mediator.MapSceneMediator;
	
	import flash.display.Bitmap;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class MapPropertiesMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "MapPropertiesMediator";
		public static const ShowGrid:String = "ShowGrid";
		
		private var mapData:MapData;
		
		[Embed(source="assets/hill0.gif")]
		private var Tile02:Class;
		
		[Embed(source="assets/general_20_1.png")]
		private var Tile03:Class;
		
		public function MapPropertiesMediator(viewComponent:MapProperties)
		{
			super(NAME, viewComponent);
			mapProperties.zoomSlider.addEventListener(Event.CHANGE,handleZoomChange);
			mapProperties.grid.addEventListener(MouseEvent.CLICK,onGridClick);
			mapProperties.load.addEventListener(MouseEvent.CLICK,onLoad);
			mapProperties.random.addEventListener(MouseEvent.CLICK,onRandom);
		}
		
		private function onRandom(evt:MouseEvent):void {
			this.sendNotification(RandomMapCommand.RANDOM_MAP);
		}
		
		private function onLoad(evt:MouseEvent):void {
			var obj:Object = new Object();
			obj.tx = this.mapProperties.targetX.text;
			obj.ty = this.mapProperties.targetY.text;
			this.sendNotification(MapSceneMediator.MapSceneLoad,obj);
		}
		
		public function onGridClick(evt:MouseEvent):void {
			sendNotification(ShowGrid,mapProperties.grid.selected);
		}
		
		private function handleZoomChange(evt:Event=null):void {
			GlobalObject.sceneScale = mapProperties.zoomSlider.value;
		}
		
		override public function listNotificationInterests():Array {
			return [
			];
		}
		
		override public function handleNotification(notification:INotification):void {
			switch(notification.getName()) {
			}
		}
		
		public function get mapProperties():MapProperties {
			return this.viewComponent as MapProperties;
		}
		
	}
}